<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <script src="__STATIC__/password/passwordBox.min.js"></script>
    <script src="__STATIC__/password/md5.js"></script>
    <title>缴纳保证金</title>
</head>
<body>

<div class="wrap-shop">
    <div class="header">
        <p>缴纳保证金</p>
        <img src="__STATIC__/img/back.png" class="back" onclick="back_url()">
        <span><a href="javascript:confirm_recharge()">确认充值</a></span>
    </div>
    <div class="center">
        <div class="main">
            <img src="__STATIC__/img_user/qiandao.png">
            <span class="cur">保证金金额(元)<br><span style="font-size: 24px ;margin-top: 2%"><b>{if condition="$bond['bond']"}{$bond['bond']}{else/}0.00{/if}</b></span></span>
        </div>
        <div>
            <!--<h4>充值金额</h4>-->
            <input type="hidden" class="text" name="price" value="{$bond['bond']}">
            <!--<h4>充值方式</h4>-->
            <div class="pay_center">
                <ul>
                    <li>
                        <label for="radio-1-1"><img src="__STATIC__/img_user/zf-qianbao.png"><span> 钱包余额</span></label>
                        <input type="radio" id="radio-1-1" name="radio-1-set" class="radio" checked/>
                    </li>
                </ul>
            </div>
        </div>
        <div id="alipay"></div>
    </div>
</div>
<script src="__STATIC__/js/layer_mobile/layer.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    function confirm_recharge() {
        var price = $("[name='price']").val();

        var zz = /^-?\d+\.?\d{0,2}$/;
        if (price == '') {
            layer.open({content: '充值金额不能为空', skin: 'msg', time: 2});
            return false;
        } else if (!zz.test(price)) {
            layer.open({content: '充值金额格式有误', skin: 'msg', time: 2});
            return false;
        } else if (price < 0.01) {
            layer.open({content: '充值金额格式有误', skin: 'msg', time: 2});
            return false;
        }
        dialog_pay();
//        $.ajax({
//            url: "{:url('mobile/bond/balance')}",
//            type: 'post',
//            dataType: 'json',
//            data: {'price': price, 'goods_id': "{$bond['id']}"},
//            success: function (data) {
//                layer.open({content: '保证金充值成功', skin: 'msg', time: 3});
//            },
//            error: function () {
//                layer.open({content: '网络繁忙,请重试', skin: 'msg', time: 2});
//            }
//        })

    }

    function dialog_pay(){
        var price = $("[name='price']").val();
        /**
         * init传入参数依次是：正确密码(传空时不对比输入是否正确),密码键盘背景，标题，副标题
         * */
        var msg = '<a href="javascript:pwd(1);">您还未设置密码,点击去设置</a>';
        if ('{$pass}'){
            msg = "<a href='javascript:pwd(2);' style='float: left;margin-left:10% ;'>修改密码</a>" +
                    "<a href='javascript:pwd(3);' style='float: right;margin-right:10% ;'>忘记密码</a>";
        }

        PwdBox.init('{$pass}', "/password/pwd_keyboard.png", '请输入支付密码', '');
        $('.notice').html(msg);
        if (!'{$pass}'){  //若没有设置密码,则移除按键
            $('.input-box').remove();
        }
        /**
         *res格式：{status:'true或false',password:'用户输入的密码'}
         *
         */
        PwdBox.show(function (res) {
            $.post("{:url('mobile/bond/balance')}",{'pwd':res.password,'price': price, 'goods_id': "{$bond['id']}"},function (data) {
                if (data.code == 200){
                    sessionStorage.removeItem('oid');
                    layer.open({content:data.message,skin:'msg'});
                    setTimeout(function () {
                        //跳转到我的全部订单
                        layer.open({content: '保证金充值成功', skin: 'msg', time: 3});

                        window.location.href = "{:url('mobile/auction/spot')}?id="+"{$bond['id']}";
                    },2000);

                } else {
                    layer.open({content:data.message,skin:'msg',time:2});
                }
            })
        });
    }


    //跳转支付密码操作页面
    function pwd(type){
        sessionStorage.setItem('pay_url',window.location.href);  //设置返回路径
        switch (type){
            case 1: //设置密码
                if ('{$info.wechat_id}' && !'{$info.username}'){  //微信登录并且未绑定手机号直接跳过手机验证
                    window.location.href = "{:url('mobile/pay_pass/check')}?act=set&paying";
                }else{   //(手机登录)去验证手机号
                    window.location.href = "{:url('mobile/pay_pass/edit')}?act=set&paying";
                }
                break;
            case 2: //修改密码
                window.location.href = "{:url('mobile/pay_pass/check')}?act=edit&paying";
                break;
            case 3: //忘记密码
                if ('{$info.wechat_id}' && !'{$info.username}') {  //微信登录并且未绑定手机号直接跳过手机验证
                    window.location.href = "{:url('mobile/pay_pass/check')}?act=forget&paying";
                }else{  //(手机登录)去验证手机号
                    window.location.href = "{:url('mobile/pay_pass/edit')}?act=forget&paying";
                }
                break;
        }
    }

    function back_url() {
        window.location.href = "{:url('mobile/auction/auction_list')}";
    }

</script>
</body>
</html>